Global Variables
Generally contains functions that were modified to do something different or added to existing global tables.
Constants
sm.types
A lookup table that maps type names to their numeric type IDs and the IDs back to their names. It is more complete than the game's own sm.types, as it also includes userdata such as Uuid, Vec3, Quat, Color, Shape, Body, Interactable, Joint, Player, Character, GuiInterface and many more.
print(sm.types["Vec3"]) -- 10003
print(sm.types[10003]) -- "Vec3"
print(sm.types[3]) -- "number"
When unsafe-env is enabled, sm is the game's real sm table, so sm.types will be the game's own (less complete) version instead.
Functions
print
print( ... )
Prints text to the chat. Will be always converted to a string so you can pass in anything.
If it is a table. It will convert to be printable and you can see the contents inside.
Arguments:
- ... [ any[] ] All arguments to send to the chat.
alert
alert( message, duration, player )
Same as the print function but sends it as a alert message.
This function is deprecated and will be removed in a future update. Calling it no longer shows an alert, it only prints a deprecation warning to the console (sc.console). Use print instead.
Arguments:
- message [ any[] ] The message to send
- duration [ any[] ] The duration before the alert message fades-out
- player [ Player? ] The player to send to.
loadstring
loadstring( code, env, bytecodeMode )
Excecutes code from a string, it can also load bytecode!
Loading bytecode works in both the safe and unsafe env.
Arguments:
- code [ string ] The code to excecute.
- env [ table ] The code environment.
- bytecodeMode [ boolean ] Whether you are trying to excecute bytecode or not.
tostring
tostring( data )
Like the normal but modified to have additional features like printing lua tables!
Arguments:
- data [ any ] The variable to convert to be a string.
debug
debug( ... )
The debug function is basically Lua's implementation of the print function in Scrap Mechanic.
Arguments:
- ... [ any[] ] All arguments to send to the console.
sleep
sleep( time )
Makes the code pause for the specified time at that particular place, maximum wait is 5 seconds.
This function is deprecated and will be removed in a future update. Calling it no longer pauses your code, it only prints a deprecation warning to the console (sc.console). Do not rely on it for timing; use onUpdate and the sc.time functions (or your own tick counters) instead.
Arguments:
- time [ number ] The time to sleep in seconds.
math.createpid
math.createpid( processID )
This function creates a PID process with the provided id. This system allows for multiple computers to access any pid process they want as they run in the background globally.
Arguments:
- processID [ number ] The id of the PID process.
math.removepid
math.removepid( processID )
This function removes a PID process with the provided id. This system allows for multiple computers to access any pid process they want as they run in the background globally.
Arguments:
- processID [ number ] The id of the PID process.
math.pid
math.pid( processID, processValue, setValue, proportional, integral, derivative, integralTime, derivativeTime )
This is a mathematical PID implementation inside of ScrapComputers. A PID controller is quite well known in the space of mathematics, I would suggest looking externally for documentation. This PID implementation is also identical to the modpack to make it easier to integrate.
Arguments:
- processID [ number ] The PID process id.
- processValue [ number ] The value to process.
- setValue [ number ] The value to base the PID feedback off of.
- proportional [ number ] The proportional gain.
- integral [ number ] The integral gain.
- derivative [ number ] The derivative gain.
- integralTime [ number ] The integral delta time.
- derivativeTime [ number ] The derivative delta time.
Returns:
- [ number ] The PID multiplier output.
enumType
enumType( value )
Like type, but gives you the numeric type ID of a value instead of its name. This is useful for telling apart userdata types that type can't distinguish well. Use sm.types to convert the ID to a name and back.
Arguments:
- value [ any ] The value to get the type ID of.
Returns:
- [ integer ] The numeric type ID.